﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using CWB.Web.Configuration;

namespace CWB.Web.Misc
{
    public static class CdnManager
    {
        private static Regex cdnUrlRegex = new Regex(@"\[CdnUrl\]/?", RegexOptions.Compiled);
        private static string cdnServer = AppConfigManager.SystemSetting.CDNServer;

        public static string CDNServer
        {
            get
            {
                return cdnServer;
            }
            set
            {
                cdnServer = string.IsNullOrEmpty(value) ? "/" : value;
            }
        }

        public static string ReplaceCdnUrl(string original)
        {
            try
            {
                return cdnUrlRegex.Replace(original, CDNServer);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.Write(ex.ToString());
                return original;
            }
        }
    }
}
